using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using yW5Lib;

namespace yWriter6
{
	[DesignerGenerated]
	public class frmEditBooksParts : Form
	{
		private IContainer components;

		[CompilerGenerated]
		[AccessedThroughProperty("TreeView1")]
		private TreeView _TreeView1;

		[CompilerGenerated]
		[AccessedThroughProperty("ctxMenu")]
		private ContextMenuStrip _ctxMenu;

		[CompilerGenerated]
		[AccessedThroughProperty("ToolStripMenuItem1")]
		private ToolStripMenuItem _ToolStripMenuItem1;

		[CompilerGenerated]
		[AccessedThroughProperty("DeleteToolStripMenuItem")]
		private ToolStripMenuItem _DeleteToolStripMenuItem;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdBook")]
		private Button _cmdBook;

		[CompilerGenerated]
		[AccessedThroughProperty("txtNew")]
		private TextBox _txtNew;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdPart")]
		private Button _cmdPart;

		[CompilerGenerated]
		[AccessedThroughProperty("ToolTip1")]
		private ToolTip _ToolTip1;

		private clsProject cProject;

		[field: AccessedThroughProperty("TreeView1")]
		internal virtual TreeView TreeView1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ctxMenu")]
		internal virtual ContextMenuStrip ctxMenu
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ToolStripMenuItem1")]
		internal virtual ToolStripMenuItem ToolStripMenuItem1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("DeleteToolStripMenuItem")]
		internal virtual ToolStripMenuItem DeleteToolStripMenuItem
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		internal virtual Button cmdBook
		{
			[CompilerGenerated]
			get
			{
				return _cmdBook;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdBook_Click;
				Button cmdBook = _cmdBook;
				if (cmdBook != null)
				{
					cmdBook.Click -= value2;
				}
				_cmdBook = value;
				cmdBook = _cmdBook;
				if (cmdBook != null)
				{
					cmdBook.Click += value2;
				}
			}
		}

		[field: AccessedThroughProperty("txtNew")]
		internal virtual TextBox txtNew
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		internal virtual Button cmdPart
		{
			[CompilerGenerated]
			get
			{
				return _cmdPart;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdPart_Click;
				Button cmdPart = _cmdPart;
				if (cmdPart != null)
				{
					cmdPart.Click -= value2;
				}
				_cmdPart = value;
				cmdPart = _cmdPart;
				if (cmdPart != null)
				{
					cmdPart.Click += value2;
				}
			}
		}

		[field: AccessedThroughProperty("ToolTip1")]
		internal virtual ToolTip ToolTip1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[DebuggerNonUserCode]
		protected override void Dispose(bool disposing)
		{
			try
			{
				if (disposing && components != null)
				{
					components.Dispose();
				}
			}
			finally
			{
				base.Dispose(disposing);
			}
		}

		[System.Diagnostics.DebuggerStepThrough]
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
			TreeView1 = new System.Windows.Forms.TreeView();
			ctxMenu = new System.Windows.Forms.ContextMenuStrip(components);
			ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
			DeleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
			cmdBook = new System.Windows.Forms.Button();
			txtNew = new System.Windows.Forms.TextBox();
			cmdPart = new System.Windows.Forms.Button();
			ToolTip1 = new System.Windows.Forms.ToolTip(components);
			ctxMenu.SuspendLayout();
			SuspendLayout();
			TreeView1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			TreeView1.HideSelection = false;
			TreeView1.Location = new System.Drawing.Point(12, 12);
			TreeView1.Name = "TreeView1";
			TreeView1.Size = new System.Drawing.Size(400, 402);
			TreeView1.TabIndex = 0;
			ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[2]
			{
				ToolStripMenuItem1,
				DeleteToolStripMenuItem
			});
			ctxMenu.Name = "ContextMenuStrip1";
			ctxMenu.Size = new System.Drawing.Size(123, 52);
			ToolStripMenuItem1.Name = "ToolStripMenuItem1";
			ToolStripMenuItem1.Size = new System.Drawing.Size(122, 24);
			ToolStripMenuItem1.Text = "Add";
			DeleteToolStripMenuItem.Name = "DeleteToolStripMenuItem";
			DeleteToolStripMenuItem.Size = new System.Drawing.Size(122, 24);
			DeleteToolStripMenuItem.Text = "Delete";
			cmdBook.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			cmdBook.Location = new System.Drawing.Point(272, 425);
			cmdBook.Name = "cmdBook";
			cmdBook.Size = new System.Drawing.Size(67, 30);
			cmdBook.TabIndex = 1;
			cmdBook.Text = "Book";
			ToolTip1.SetToolTip(cmdBook, "Create a new book with the given title");
			cmdBook.UseVisualStyleBackColor = true;
			txtNew.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			txtNew.Location = new System.Drawing.Point(12, 429);
			txtNew.Name = "txtNew";
			txtNew.Size = new System.Drawing.Size(245, 22);
			txtNew.TabIndex = 2;
			cmdPart.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			cmdPart.Location = new System.Drawing.Point(345, 425);
			cmdPart.Name = "cmdPart";
			cmdPart.Size = new System.Drawing.Size(67, 30);
			cmdPart.TabIndex = 1;
			cmdPart.Text = "Part";
			ToolTip1.SetToolTip(cmdPart, "Create a new part in the selected book");
			cmdPart.UseVisualStyleBackColor = true;
			base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 16f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(422, 466);
			base.Controls.Add(TreeView1);
			base.Controls.Add(cmdPart);
			base.Controls.Add(txtNew);
			base.Controls.Add(cmdBook);
			base.Name = "frmSetupBooks";
			base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			Text = "Setup Books and Parts";
			ctxMenu.ResumeLayout(false);
			ResumeLayout(false);
			PerformLayout();
		}

		public frmEditBooksParts(ref clsProject ProjectClass)
		{
			base.Load += frmSetupBooks_Load;
			InitializeComponent();
			cProject = ProjectClass;
		}

		private void frmSetupBooks_Load(object sender, EventArgs e)
		{
			FillTree();
		}

		private void FillTree()
		{
			TreeView1.Nodes.Clear();
			IEnumerator enumerator = default(IEnumerator);
			try
			{
				enumerator = cProject.Books.GetEnumerator();
				IEnumerator enumerator2 = default(IEnumerator);
				while (enumerator.MoveNext())
				{
					clsBook clsBook = (clsBook)enumerator.Current;
					TreeNode treeNode = TreeView1.Nodes.Add(Conversions.ToString(clsBook.ID), clsBook.Title, "Book");
					treeNode.Tag = Conversions.ToString(clsBook.ID);
					treeNode.ContextMenuStrip = ctxMenu;
					try
					{
						enumerator2 = cProject.Parts.GetEnumerator();
						while (enumerator2.MoveNext())
						{
							clsPart clsPart = (clsPart)enumerator2.Current;
							if (clsPart.BelongsToBookID == clsBook.ID)
							{
								TreeNode treeNode2 = treeNode.Nodes.Add(Conversions.ToString(clsPart.ID), clsPart.Title, "Part");
								treeNode2.Tag = Conversions.ToString(clsPart.ID);
								treeNode2.ContextMenuStrip = ctxMenu;
							}
						}
					}
					finally
					{
						if (enumerator2 is IDisposable)
						{
							(enumerator2 as IDisposable).Dispose();
						}
					}
				}
			}
			finally
			{
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
			}
			TreeView1.ExpandAll();
		}

		private void cmdBook_Click(object sender, EventArgs e)
		{
			clsBook cBook = new clsBook();
			cBook.Title = txtNew.Text;
			cProject.AddBook(ref cBook);
			TreeView1.Nodes.Add(Conversions.ToString(cBook.ID), cBook.Title, "Book").Tag = Conversions.ToString(cBook.ID);
		}

		private void cmdPart_Click(object sender, EventArgs e)
		{
			clsPart cPart = new clsPart();
			TreeNode selectedNode = TreeView1.SelectedNode;
			if (selectedNode == null)
			{
				Interaction.MsgBox("Please select a book to add this part to");
				return;
			}
			if (Operators.CompareString(selectedNode.ImageKey, "Part", TextCompare: false) == 0)
			{
				Interaction.MsgBox("You can't add a part to another part. Please select a book instead.");
				return;
			}
			clsBook clsBook = cProject.get_BookByID(Conversions.ToInteger(selectedNode.Tag));
			cPart.BelongsToBookID = clsBook.ID;
			cPart.Title = txtNew.Text;
			cProject.AddPart(ref cPart);
			selectedNode.Nodes.Add(Conversions.ToString(cPart.ID), cPart.Title, "Part");
		}
	}
}
